using ExampleWebApplication.Entities;
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;

namespace ExampleWebApplication.Infraestruture.NHibernate.EntityMappings
{
    public class CustomerMap : ClassMapping<Customer>
    {
        public CustomerMap()
        {
            Table("Customers");
            Id(x => x.CustomerID, map => { map.Generator(Generators.Assigned); map.Column("CustomerID"); });
            Property(x => x.CompanyName, map => { map.Column("CompanyName"); map.NotNullable(true); map.Length(40); });
            Property(x => x.ContactName, map => { map.Column("ContactName"); map.Length(30); });
            Property(x => x.ContactTitle, map => { map.Column("ContactTitle"); map.Length(30); });
            Property(x => x.Address, map => { map.Column("Address"); map.Length(60); });
            Property(x => x.City, map => { map.Column("City"); map.Length(15); });
            Property(x => x.Region, map => { map.Column("Region"); map.Length(15); });
            Property(x => x.PostalCode, map => { map.Column("PostalCode"); map.Length(10); });
            Property(x => x.Country, map => { map.Column("Country"); map.Length(15); });
            Property(x => x.Phone, map => { map.Column("Phone"); map.Length(24); });
            Property(x => x.Fax, map => { map.Column("Fax"); map.Length(24); });
            Property(x => x.Bool, map => map.Column("Bool"));
            Bag(x => x.CustomerCustomerDemos, map => { map.Inverse(true); map.Key(key => key.Column("CustomerID")); }, rel => rel.OneToMany());
            Bag(x => x.Orders, map => { map.Inverse(true); map.Key(key => key.Column("CustomerID")); }, rel => rel.OneToMany());
        }
    }
}
